<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resource/css/default.css" />
		<link rel="stylesheet" type="text/css" href="${contextPath}/resource/tree/zTreeStyle/zTreeStyle.css" />
		<script type="text/javascript" src="${contextPath}/resource/tree/jquery-1.4.2.js"></script>
		<script type="text/javascript" src="${contextPath}/resource/tree/jquery.ztree-2.6.js"></script>
		
		<script language="JavaScript">
var zTree1;
var setting;
setting = {
	isSimpleData : true,
	treeNodeKey : "id",
	treeNodeParentKey : "pId",
	showIcon : false,
	checkable : true,
	checkStyle : "radio",
	checkRadioType : "all",
	callback : {
		change : zTreeOnChange
	}
};

$(document).ready(function() {
	refreshTree();
	getCheckedrefreshTree();
});

var treeDb = ${jsonTree};
//设置单选框被选中的值 
var checkValue = '${user.blngOrgNo}';
for(var i=0;i<treeDb.length;i++){
	if(treeDb[i].id == checkValue){
		treeDb[i].checked = true;
	}
}
	function zTreeOnChange(event, treeId, treeNode) {
		getCheckedNodesLength();
	}
	function refreshTree() {
		zTree1 = $("#radioAgencyId").zTree(setting, treeDb);
		getCheckedNodesLength();
	}

	function getCheckedNodesLength() {
		var tmp = zTree1.getCheckedNodes(true);
		if(tmp.length>0){
		   document.getElementById("user.blngOrgNo").value =tmp[0].id;
		}
	}

var treeDb1  = ${jsonTree};
//取得多选框数中被选中的值，并设置被选中 
var checkValues ="${user.brwsOrgNo}";
var butgrpVales={"":""};
if(checkValues != null && checkValues != "" ){
	var butts =checkValues.split("");
	for(var i=0;i<butts.length;i++){
		var flg = butts[i];
		if(flg=="1"){
			var sval ="1";
			for(var j=butts.length-i;j>1;j--){
				sval = sval+"0";
			}
			butgrpVales[sval]=sval;
		}
	}
}
for(var i=0;i<treeDb1.length;i++){
	if(treeDb1[i].arGrp == butgrpVales[treeDb1[i].arGrp]){
		treeDb1[i].checked = true;
	}
}


var zTreeCheck;
	var settingCheck;
		settingCheck = {
		isSimpleData: true,
		treeNodeKey: "id",
		treeNodeParentKey: "pId",
        showIcon :false,
			checkable: true,
			callback: {
				change:	zTreeOnChangeCheck_lh
			}
		};

	
	function zTreeOnChangeCheck_lh(event, treeId, treeNode) {
		getCheckedNodesLength_lh();
	}

	function getCheckBoxType() {
		
		var type = { "Y":'s', "N":'s'};
		return type;
	}

	function getCheckedrefreshTree() {
		var checkType = getCheckBoxType();
		settingCheck.checkType = checkType;
		zTreeCheck = $("#checkViewagencyId").zTree(settingCheck, treeDb1);
	}

	function getCheckedNodesLength_lh() {
		var tmp = zTreeCheck.getCheckedNodes();
	    var viewagencyIds="" ;
		for(var i = 0;i<tmp.length;i++){
		   if(i==tmp.length-1){
		   viewagencyIds +=tmp[i].arGrp;
		   }else{
		   viewagencyIds +=tmp[i].arGrp+",";
		   }
		}
		document.getElementById("user.brwsOrgNo").value =viewagencyIds;
	}
	function submitFrom(fm){
			var lat = document.getElementById("nslatLong").value;
			var lot = document.getElementById("welatLong").value;
			var lat1 = document.getElementById("latitude1").value;
			var lat2 = document.getElementById("latitude2").value;
			var lat3 = document.getElementById("latitude3").value;
			var lot1 = document.getElementById("longitude1").value;
			var lot2 = document.getElementById("longitude2").value;
			var lot3 = document.getElementById("longitude3").value;
			
			if(lat1!="" || lat2!="" || lat3!="" || lot1!="" || lot2!="" || lot3!=""){
				var latValues = parseFloat(lat1) + parseFloat(lat2)/60.0+ parseFloat(lat3)/60.0/60.0;
				var lotValues = parseFloat(lot1) + parseFloat(lot2)/60.0+ parseFloat(lot3)/60.0/60.0;
				if(isNaN(latValues)){
					alert("请输入纬度！");
					return;
				}
				if(isNaN(lotValues)){
					alert("请输入经度！");
					return;
				}
				if(latValues>90.0){
					alert("纬度超出范围请修改!");
					return;
				}
				if(lotValues>180.0){
					alert("经度超出范围请修改!");
					return;
				}
				if(parseFloat(lat2)>=60 || parseFloat(lot2)>=60){
					alert("分数超出范围请修改!");
					return;
				}
				if(parseFloat(lat3)>=60 || parseFloat(lot3)>=60){
					alert("秒数超出范围请修改!");
					return;
				}
				document.getElementById("user.wellat").value = lat + latValues;
				document.getElementById("user.wellog").value = lot + lotValues;
			}
		fm.submit();
	}
	
	//1.控制键盘输入，只允许数字键录入整数
function intOnly(object) {
	if(object.value == "-"){
		alert("请输入正整数数字!");
		object.value = "";
	}
	var s = parseInt(object.value);
	if(isNaN(s)){
		alert("请输入正整数数字!");
		object.value = "";
	}else{
	 	object.value = s;
	}
}
//2.控制键盘输入，只允许数字键录入小数和整数
function numberOnly(object) {
	var st = object.value;
	if(st.indexOf(".")==0){
	 	alert("请输入数字");
	 	object.value = "";
	}else if(st.indexOf(".")+1 == st.length){
	}else{
		var s = parseFloat(st);
		if(isNaN(s)){
	 		alert("请输入数字");
	 		object.value = "";
	 	}
		if(isNaN(object.value)){
			alert("请输入数字");
			object.value = "";
		}
	}
}
</script>
</head>
<body>
		<s:form action="userAction_update.do" namespace="/user" method="post" onsubmit="getCheckedNodesLength_lh()">
			<table class="menu_table">
				<tr>
					<th>
						<a href="userAction_list.do">用户管理</a>&gt;&gt;编辑用户
					</th>
				</tr>
			</table>
			<div class="listtable">
				<div class="secondDiv">
					<table class="form_table">
						
						<tr>
							<th width="20%">
								登录名
							</th>
							<td>
								<s:text name="user.signNm" />
								
							</td>
							<th>
								状态
							</th>
							<td>
								<s:radio name="user.vldMrk" list="#{'1':'正常','0':'锁定'}"></s:radio>
								<span class="txtblue" id="resultadminUser">*</span>
							</td>
							<s:hidden name="user.arNo"></s:hidden>
							<s:hidden name="user.userId"></s:hidden>
							<s:hidden name="user.userPw"></s:hidden>
							<s:hidden name="user.ltstSignTm"></s:hidden>
							<s:hidden name="user.signNm"></s:hidden>
						</tr>
						<tr>
							<th>
								真实姓名
							</th>
							<td width="15%">
								<s:textfield name="user.userName" id="user.userName"
									maxlength="50" size="20"></s:textfield>
							</td>
							<th width="20%">
								固定电话
							</th>
							<td width="35%">
								<s:textfield name="user.fxTel" id="user.fxTel" size="20"
									maxlength="30" />
							</td>
						</tr>
						<tr>
							<th>
								移动电话
							</th>
							<td>
								<s:textfield name="user.mobl" id="user.mobl" size="20"
									maxlength="30" onblur="javaScript:" />
							</td>
							<th>
								电子邮件
							</th>
							<td>
								<s:textfield name="user.email" id="user.email" size="20"
									maxlength="50" />
							</td>
						</tr>
						<tr>
							<th>
								登录纬度
								<s:hidden name="user.wellat" id="user.wellat"></s:hidden>
								<s:hidden name="user.wellog" id="user.wellog" ></s:hidden>
							</th>
							<td>
								 <select name="nslatLong" id="nslatLong">
			    					<option value="+">北纬</option>
			    					<option value="-">南纬</option>
					 			</select>：<s:textfield name="latitude1" id="latitude1" size="1" onkeyup="intOnly(this);"/>°
					 			<s:textfield name="latitude2" id="latitude2" size="1" onkeyup="intOnly(this);"/>'
					 			<s:textfield name="latitude3" id="latitude3" size="2" onkeyup="numberOnly(this);"/>"
							</td>
							<th>
								登录经度
							</th>
							<td>
								 <select name="welatLong" id="welatLong">
			    					<option value="+">东经</option>
			    					<option value="-">西经</option>
								</select>：<s:textfield name="longitude1" id="longitude1" size="1" onkeyup="intOnly(this);"/>°
					 			<s:textfield name="longitude2" id="longitude2" size="1" onkeyup="intOnly(this);"/>'
					 			<s:textfield name="longitude3" id="longitude3" size="2" onkeyup="numberOnly(this);"/>"
							</td>
						</tr>
						<tr>
							<th>
								所属角色
							</th>
							<td colspan="3">
								<s:checkboxlist list="roleMap" name="roleIdValues"></s:checkboxlist>
								<span class="txtblue" id="resultadminUser">*</span>
							</td>
						</tr>
						<tr>
							<th>
								所属机构
							</th>
							<s:hidden name="user.blngOrgNo" id="user.blngOrgNo"></s:hidden>
							<td>
								<div class="zTreeDemoBackground">
									<ul id="radioAgencyId" class="tree"></ul>
								</div>
							</td>
							<th>
								浏览机构信息
							</th>
							<s:hidden name="user.brwsOrgNo" id="user.brwsOrgNo"></s:hidden>
							<td>
								<div class="zTreeDemoBackground">
									<ul id="checkViewagencyId" class="tree"></ul>
								</div>
							</td>
						</tr>
						<tr>
							<th>
								描述
							</th>
							<td colspan="3">
								<s:textarea name="user.dtlDesc" rows="4" cols="60"
									maxlength="500"></s:textarea>
							</td>
						</tr>
					</table>
					
		<table width="50%" border="0" align="center" cellpadding="3" cellspacing="1">
			<s:token></s:token>
		    <tr>
		      <td align="center"  >
		      <div align="center">
		       	<input type="button" value="" class="apply_style" align="middle" onclick="submitFrom(this.form);"/>
		        <input type="button" onclick="javascript:location='userAction_list.do'" class="back_style"  />
		        <input type="reset" id="重置 " class="reset_style" value=""/>
		       </div>
		       </td>
		    </tr>
		</table>
				</div>
			</div>
		</s:form>
	</body>
	<script language="JavaScript">
function  convertNUM(beforeCountTest) {  
     if((beforeCountTest.toString().indexOf('E') != -1) || (beforeCountTest.toString().indexOf('e') != -1)){  
         var  regExp =  new  RegExp( '^((\\d+.?\\d+)[Ee]{1}(\\d+))$', 'ig' );  
         var  result = regExp.exec(beforeCountTest.toString());  
         var  resultValue = "0";  
         var  power =  "" ;  
         if  (result !=  null ){  
            resultValue = result[2];  
            power = result[3];  
            result = regExp.exec(beforeCountTest.toString());  
        }  
         if  (resultValue !=  "" ) {  
             if  (power !=  "" ) {  
                 var  powVer = Math.pow(10, power);  
                 resultValue = resultValue * powVer;  
            }  
        }  
        return resultValue;
    }else{
    	return beforeCountTest.toString();
    } 
}
	var lat ="${user.wellat}";
	var log ="${user.wellog}";
	if(lat != "" && log !="" ){
		var lat1 = lat.substring(0,1);
		var lat2 = 0;
		var lat3 = 0;
		var lat4 = 0;
		if(lat.indexOf(".") > 0){
			lat2 = lat.substring(1,lat.indexOf("."));
			values = (parseFloat(lat.substring(1))-parseFloat(lat2))*60;
			lat3 = values.toString().substring(0,values.toString().indexOf("."));
			val = convertNUM(60*(values-lat3));
		 	lat4= parseFloat(val.substring(0,val.indexOf(".")+4));
		}else{
			lat2 =lat.substring(1);
		}
		
		
		document.getElementById("nslatLong").value =lat1;
		document.getElementById("latitude1").value =lat2;
		document.getElementById("latitude2").value =lat3;
		document.getElementById("latitude3").value =lat4;

		var log1 = log.substring(0,1);
		var log2 = 0;
		var log3 = 0;
		var log4 = 0;
		if(log.indexOf(".")>0){
			log2 = log.substring(1,log.indexOf("."));
			lvalues = (parseFloat(log.substring(1))-parseFloat(log2))*60;
			log3 = lvalues.toString().substring(0,lvalues.toString().indexOf("."));
			lval = convertNUM(60*(lvalues-log3));
			log4= parseFloat(lval.toString().substring(0,lval.toString().indexOf(".")+4));
		}else{
			log2 = log.substring(1);
		}
		document.getElementById("welatLong").value =log1;
		document.getElementById("longitude1").value =log2;
		document.getElementById("longitude2").value =log3;
		document.getElementById("longitude3").value =log4;
		
	}
	</script>
</html>
